﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "Bullet/RuleBullet.h"

#include "Components/SphereComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Particles/ParticleSystemComponent.h"


ARuleBullet::ARuleBullet()
{
	PrimaryActorTick.bCanEverTick = true;

	// ParticleMesh = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("BulletParticleMesh"));
	BoxDamage = CreateDefaultSubobject<USphereComponent>(TEXT("BulletBoxDamage"));
	RootBullet = CreateDefaultSubobject<USceneComponent>(TEXT("BulletRoot"));
	ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("BulleProjectileMovement"));

	RootComponent = RootBullet;
	BoxDamage->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
	// ParticleMesh->AttachToComponent(BoxDamage, FAttachmentTransformRules::KeepRelativeTransform);
	

	// 设置子弹初始速度
	ProjectileMovement->InitialSpeed = 1600.f;
	ProjectileMovement->MaxSpeed = 2000.f;
	// 子弹重力
	ProjectileMovement->ProjectileGravityScale = 0.0f;

	// 生命时间
	InitialLifeSpan = 4.0f;
}


void ARuleBullet::BeginPlay()
{
	Super::BeginPlay();

	BoxDamage->OnComponentBeginOverlap.AddUniqueDynamic(this, &ARuleBullet::BeginOverlap);
}

void ARuleBullet::BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	UE_LOG(LogTemp, Warning, TEXT("碰撞到：%s"), *OtherActor->GetName());
}


void ARuleBullet::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

